#include <stdio.h>
#include "../inc/mzrtos.h"

static struct mz_list_node mz_object_list[MZ_OBJECT_MAX];

static void _mz_object_init(mz_object_t object,
                            const char* name,
                            mz_uint8_t type){
    mz_list_init(&object->list);

    mz_strcpy(object->name, name);

    object->type = type;
    /* Insert into kernel object list */
    mz_list_insert_before(&mz_object_list[type], &object->list);
}

void mz_object_init(mz_object_t object,
                    const char* name,
                    mz_uint8_t type){
    _mz_object_init(object, name, type);
}

mz_list_t mz_object_show(mz_object_type_t type){
    if(type == MZ_OBJECT_MAX)
        /* If equal to the maximum number, it indicates that all kernel objects need to be obtained */
        return mz_object_list;
    return &mz_object_list[type];
}

/* This function is only used for debugging to see if it is properly inserted into the kernel object list */
void mz_object_debug(mz_object_type_t type){
    mz_list_t temp = mz_object_show(type);
    mz_list_t l = temp;
    mz_object_t object = MZ_NULL;

    for(; l->next != temp; l = l->next){
        object = mz_list_entry(l->next,
                          struct mz_object,
                          list);
        printf("object:%s\n", object->name);
    }
}

void mz_object_system_init(void){
    mz_uint32_t i;
    for(i = 0; i < MZ_OBJECT_MAX; i++){
        mz_list_init(&mz_object_list[i]);
    }
}